package com.auroramanito.uaa.security.userdetails;

import com.auroramanito.uaa.repository.UserRepo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    private final UserRepo userRepo;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //Optional类型
        return userRepo.findOptionalByUsername(username)
                .orElseThrow(() ->new UsernameNotFoundException("未找到用户名为" + username + "的用户"));
    }
}
